package com.appinfo.controller.dev;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.appinfo.entity.DevUser;
import com.appinfo.service.DevUserService;

/**
 * 开发者登录管理
 * @author Administrator
 *
 */
@Controller
public class DevLoginController {

	@Autowired
	DevUserService devUserService;
	
	
	//跳转到开发者登录页面
	@RequestMapping("/dev/login")
	public String toDevLogin(){
		return "devlogin";
	}
	@RequestMapping("/dev/dologin")
	public String doLogin(String devCode,String devPassword,
			HttpSession session,
			Model model){
		
		 DevUser devUser = devUserService.login(devCode, devPassword);
		 if(devUser != null){
			 session.setAttribute("devUserSession", devUser);
			 return "developer/main";
		 }
		 model.addAttribute("error", "用户名密码错误");
		return "devlogin";
	}
	
	//开发者注销
	@RequestMapping("/dev/logout")
	public String logout(HttpSession session){
		session.removeAttribute("devUserSession");
		return "devlogin";
	}
}
